package org.example.leetcode.codeExecutor.utils;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.api.model.StreamType;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.command.PullImageResultCallback;

import java.io.Closeable;
import java.io.IOException;

public class DockerUtils {
    public static void main(String[] args) {
        SSHTools.SSHResult dockerMemory = SSHTools.getDockerMemory();
        System.out.println(dockerMemory);
//        DockerClient dockerClient= DockerClientBuilder.getInstance("tcp://47.101.182.243:2375").build();
//        dockerClient.pullImageCmd("c_container").exec(new PullImageResultCallback());
//        CreateContainerResponse zhc0317 = dockerClient.createContainerCmd("c_container").exec();
//        String id = zhc0317.getId();
//        System.out.println("启动容器");
//        dockerClient.startContainerCmd(id).exec();
//        ExecCreateCmdResponse response = dockerClient.execCreateCmd(id)
//                .withCmd(new String[]{"ls"})
//                .withAttachStderr(true)
//                .withAttachStdin(true)
//                .withAttachStdout(true)
//                .exec();
//        String responseId=response.getId();
//        System.out.println(responseId);
//        dockerClient.execStartCmd(responseId).exec(new ResultCallback<Frame>() {
//            @Override
//            public void onStart(Closeable closeable) {
//                System.out.println("开始执行");
//            }
//
//            @Override
//            public void onNext(Frame object) {
//                StreamType streamType=object.getStreamType();
//                if(StreamType.STDERR.equals(streamType)){
//                    System.out.println("错误"+new String(object.getPayload()));
//                }
//                else{
//                    System.out.println(new String(object.getPayload()));
//                }
//
//            }
//
//            @Override
//            public void onError(Throwable throwable) {
//
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//
//            @Override
//            public void close() throws IOException {
//
//            }
//        });
    }
}
